import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'

Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/',
      redirect:'/login',
      // name: 'HelloWorld',
      // component: HelloWorld
    },
    {
      path: '/index',
      name: 'Index',
      component: () => import('@/views/index')
    },
    {
      path: '/login',
      name: 'Login',
      component: () => import('@/views/login')
    },
    {
      path: '/home',
      name: 'Home',
      component: () => import('@/views/Home'),
      redirect: '/welcome',
      children:[
        {
          path:'/welcome',
          component: () => import('@/components/Welcome'),
        },
        {
          path:'/user',
          component: () => import('@/components/user/Users'),
        },
      ]
    }
  ]
})

//挂载路由导航守卫
router.beforeEach((to,from,next)=>{
  //to将要访问的路径
  //from代表从哪个路径跳转而来
  //next是一个函数，表示放行
  //  next()放行 next('login') 强制跳转
  // if(to.path==='/login')  return next()
  // const tokenStr = window.sessionStorage.getItem('token')
  // if(!tokenStr) return next('/login')
  next()
})
export default router